//
//  QTHomefamousCell.m
//  QTLifeCircle
//
//  Created by 王琼 on 17/1/16.
//  Copyright © 2017年 徐腾. All rights reserved.
//

#import "QTHomefamousCell.h"
#import"QTfamousCVCell.h"
#import"UIColor+CZAddition.h"
#import "QTLifeCircleNetworkingTool.h"
#import "QTFmousModel.h"
#import <YYModel.h>
//处理点击跳转的
#import "QTFamousChildController.h"

#define screenW [UIScreen mainScreen].bounds.size.width
@interface QTHomefamousCell()<UICollectionViewDataSource,UICollectionViewDelegate>

@property (weak, nonatomic) IBOutlet UICollectionView *famousColleView;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;

@end

@implementation QTHomefamousCell

//数据传进来如果显示不出来视图,就写set方法
- (void)setFamousModelList:(NSArray *)famousModelList {
    
    _famousModelList = famousModelList;
    
    NSLog(@"%@",famousModelList);
    
    if (famousModelList != nil) {
        
        [self.famousColleView reloadData];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    // 
    self.flowLayout.itemSize = CGSizeMake(screenW/2-1, self.bounds.size.height / 2);
    self.flowLayout.minimumLineSpacing = 1;
    self.flowLayout.minimumInteritemSpacing = 1;
    self.famousColleView.delegate = self;
    self.famousColleView.dataSource = self;
    self.famousColleView.bounces = NO;
    self.famousColleView.scrollEnabled = NO;
    
    
    
}

//在当前cell中加载数据,并赋值给cell中的cell

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 4;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    QTfamousCVCell* cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"famousCell" forIndexPath:indexPath];
    
    //------第一个cell数据处理------
    //将collectionView的item的model属性赋值
    cell.model = self.famousModelList[indexPath.item];
    
    //------第一个cell数据处理------
   
    //  cell.backgroundColor = [UIColor cz_randomColor];
    return cell;
}




//当指定indexPath处的item被选择时触发 //didSelectItemAtIndexPath (执行选择事件)
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //QTFamousChildController* conVC = [[UIStoryboard storyboardWithName:@"QTFamousChildController" bundle:nil]instantiateViewControllerWithIdentifier:@"ChildControll"];
    //在这里将数据传给控制器
    /*
     1.写一个代理 去一个名字
     
    */
    //判断方法有没有实现
    if([self.delegate respondsToSelector:@selector(pushToController:)])
    {
        
        [self.delegate pushToController:self.famousModelList[indexPath.item]];
    }
    
}



//当indexPath.item被点击时 向下执行(如果返回YES则向下执行，否则执行到这里为止)
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
    
    return YES;
}

//手指点击时,高亮
- (void)collectionView:(UICollectionView *)collectionView didHighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
   
}


//手指松开 取消高亮
- (void)collectionView:(UICollectionView *)collectionView didUnhighlightItemAtIndexPath:(NSIndexPath *)indexPath
{
   
}

@end
